package com.linb.pan.server.modules.file.converter;

import com.linb.pan.server.modules.file.context.*;
import com.linb.pan.server.modules.file.entity.BPanUserFile;
import com.linb.pan.server.modules.file.po.*;
import com.linb.pan.server.modules.file.vo.BPanUserFileVO;
import com.linb.pan.storage.engine.core.context.StoreFileChunkContext;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;

@Mapper(componentModel = "spring")
public interface FileConverter {

    @Mapping(target = "parentId", expression = "java(com.linb.pan.core.utils.IdUtil.decrypt(createFolderPO.getParentId()))")
    @Mapping(target = "userId", expression = "java(com.linb.pan.server.common.utils.UserIdUtil.get())")
    CreateFolderContext createFolderPOToCreateFolderContext(CreateFolderPO createFolderPO);

    @Mapping(target = "fileId", expression = "java(com.linb.pan.core.utils.IdUtil.decrypt(po.getFileId()))")
    @Mapping(target = "userId", expression = "java(com.linb.pan.server.common.utils.UserIdUtil.get())")
    UpdateFilenameContext updateFilenamePOToUpdateFilenameContext(UpdateFilenamePO po);

    @Mapping(target = "userId", expression = "java(com.linb.pan.server.common.utils.UserIdUtil.get())")
    DeleteFileContext deleteFilePOToDeleteFileContext(DeleteFilePO deleteFilePO);

    @Mapping(target = "parentId", expression = "java(com.linb.pan.core.utils.IdUtil.decrypt(secUploadPO.getParentId()))")
    @Mapping(target = "userId", expression = "java(com.linb.pan.server.common.utils.UserIdUtil.get())")
    SecUploadContext secUploadPOToSecUploadContext(SecUploadPO secUploadPO);

    @Mapping(target = "parentId", expression = "java(com.linb.pan.core.utils.IdUtil.decrypt(fileUploadPO.getParentId()))")
    @Mapping(target = "userId", expression = "java(com.linb.pan.server.common.utils.UserIdUtil.get())")
    FileUploadContext fileUploadPOToFileUploadContext(FileUploadPO fileUploadPO);

    @Mapping(target = "record", ignore = true)
    FileSaveContext fileUploadContextToFileSaveContext(FileUploadContext fileUploadContext);

    @Mapping(target = "userId", expression = "java(com.linb.pan.server.common.utils.UserIdUtil.get())")
    FileChunkUploadContext fileChunkUploadPOToFileChunkUploadContext(FileChunkUploadPO fileChunkUploadPO);

    FileChunkSaveContext fileChunkUploadContextToFileChunkSaveContext(FileChunkUploadContext fileChunkUploadContext);

    @Mapping(target = "realPath", ignore = true)
    StoreFileChunkContext fileChunkSaveContextToStoreFileChunkContext(FileChunkSaveContext context);

    @Mapping(target = "userId", expression = "java(com.linb.pan.server.common.utils.UserIdUtil.get())")
    QueryUploadedChunksContext queryUploadedChunksPOToQueryUploadedChunksContext(QueryUploadedChunksPO queryUploadedChunksPO);

    @Mapping(target = "parentId", expression = "java(com.linb.pan.core.utils.IdUtil.decrypt(fileChunkMergePO.getParentId()))")
    @Mapping(target = "userId", expression = "java(com.linb.pan.server.common.utils.UserIdUtil.get())")
    FileChunkMergeContext fileChunkMergePOToFileChunkMergeContext(FileChunkMergePO fileChunkMergePO);

    FileChunkMergeAndSaveContext fileChunkMergeContextToFileChunkMergeAndSaveContext(FileChunkMergeContext fileChunkMergeContext);

    @Mapping(target = "label", source = "bPanUserFile.filename")
    @Mapping(target = "id", source = "bPanUserFile.fileId")
    @Mapping(target = "children", expression = "java(com.google.common.collect.Lists.newArrayList())")
    FolderTreeNodeVO bPanUserFileToFolderTreeNodeVO(BPanUserFile bPanUserFile);

    BPanUserFileVO bPanUserFile2BPanUserFileVO(BPanUserFile record);

}
